<?php
// 公众号管理类
namespace Home\Controller;
// use Think\Controller;
class StatisticsController extends BaseController {
	public function index(){
		$this->display();
	}
	public function qrcode(){
		$starttime = strtotime(I('stime',date('Y-m-d')));
		$endtime = strtotime(I('ntime',date('Y-m-d')))+24*3600-1;
		$page = I('page',1);
		
		$mod = D('Qr_code');
		$cmod = D('Qr_code_count');
		
		$where = array('app_id'=>$this->app['id']);
		$count = $mod->where($where)->count();
		$data = $mod->where($where)->page($page.',20')->order('scene_id')->select();
		foreach ($data as &$v){
			$scene_id[] = $v['scene_id'];
		}
		$coun_code = $cmod->where(array('app_id'=>$this->app['id'],'scene_id'=>array('in',$scene_id),'addtime'=>array(array('gt',$starttime),array('lt',$endtime))))->getField('scene_id,count(id) as num');
		foreach ($data as &$vv){
			$vv['count'] =$coun_code[$vv['scene_id']];
		}
		
		$this->assign('page',$page);
		$this->assign('prev',($page > 1) ? $page-1 : 1);
		$this->assign('next',($page > ceil($count/20)) ? $page+1 : ceil($count/20));
		$this->assign('count',ceil($count/20));
		
		$this->assign('stime',date('Y-m-d',$starttime));
		$this->assign('ntime',date('Y-m-d',$endtime));
		
		$this->assign('data',$data);
		$this->display();
	}
}